<template>
  <!-- 商城设置  个人信息 -->
  <div class="user-set-box radius" v-if="shopInfo">
    <div class="top flex">
      <div class="head-img" v-if="checkPermi(['shopCenter:editInfo'])">
        <el-upload :action="uploadImgUrl" :show-file-list="false" list-type="picture-card" :limit="1" :on-success="handleAvatarSuccess">
          <div class="btn font12">更换LOGO</div>
          <img :src="shopInfo.avatar" alt="" />
        </el-upload>
      </div>
      <div class="head-img" v-else>
        <img :src="shopInfo.avatar" alt="" />
      </div>
      <div class="name-box">
        <div class="shopname font18 bold flex">
          
          <span v-if="shopInfo.isQuality==2&&!isEditName" >
            <youzhiName :name="shopInfo.tenantName"></youzhiName>
          </span>
          <span v-else-if="!isEditName">{{ shopInfo.tenantName }}</span>

        </div>
        <div class="id-txt">店铺ID:{{ shopInfo.tenantId }}</div>
        <div class="qianyue">
          <div class="yi flex alc"  @click="openAuth">
            <span class="icon"></span>
            <span style="color:#24A813" v-if="shopInfo.authType&&shopInfo.authType==2">已认证个人</span>
            <span style="color:#24A813" v-else-if="shopInfo.authType&&shopInfo.authType==3">已认证企业</span>
            <span v-else-if="shopInfo.authType&&shopInfo.authType==4">认证撤销中...</span>
            <span v-else >未认证 <el-button size="mini" type="primary" plain style="padding:3px 8px;margin-left:5px">立即认证</el-button> </span>
          </div>
          
          <!-- <div class="wei flex alc"><span class="icon"></span><span>未签约</span></div> -->
        </div>
    
      </div>
      <div class="other1" style="margin-left:20px;padding-top:10px">
        <el-button type="primary" size="small" @click="myHaibao">我的海报</el-button>
      </div>
    </div>
    <div style="margin-top:16px">
      <formSubTitVue :title="'我的资产'" :tip="''"></formSubTitVue>
    </div>
    <div class="zichan flex">
      
      <div class="zhanghu">
        <div class="top flex alc">
          <!-- <img class="sub-img" src="../../../../assets/img/home/account.png" alt="" /> -->
          <strong class="sub-tit font16">账户信息:</strong>
          <div class="shuaxin flex alc" @click="getInfo">
            <span class="el-icon-refresh-right"></span>
            <span class="font14">刷新</span>
          </div>

        </div>
        <div class="main-box flex fbt">
          <div class="money-box">
            <div>
              <strong class="font16">账户余额(元)</strong>
            </div>
            <strong class="money-num font24">{{ shopInfo.availableMoney||0.00 }}</strong>
            <div v-if="TIXIANING&&TIXIANING.type==1" style="color: #FFB5a1;font-size:12px;margin-bottom:5px">您有一笔 <span style="color:red;font-size:18px">{{TIXIANING.amount}}</span> 元的提现正在进行中...</div>
            <div class="btn-box">
              <el-button type="primary" class="btn" size="mini" @click="tixianFn" >
                <span class="icon"></span> 提现
              </el-button>
              <el-button v-hasPermi="['tenantPages:moneys']" type="primary" class="btn" size="mini" @click="mingxi('/shopManageByTenant/shop/moneys')">
                余额明细
              </el-button>
            </div>
          </div>
          <div class="jifen-box">
            <div>
              <strong class="font16">虞豆</strong>
            </div>

            <div class="money-num font24">{{ shopInfo.campNumber||0 }}</div>
            <div class="btn-box">
              <el-button type="primary" size="mini" class="btn" @click="chongzhijifen">
                <span class="icon"></span>
                充值
              </el-button>
              <el-button v-hasPermi="['tenantPages/jifen']" type="primary" class="btn" size="mini" @click="mingxi('/shopManageByTenant/tenantPages/jifen')">
                虞豆明细
              </el-button>
            </div>
          </div>
        </div>
      </div>
      <div class="baozhengjin" >
        <!-- <div class="subtit">
          商家保证金：
        </div> -->
        <div class="top flex alc">
          <!-- <img class="sub-img" src="../../../../assets/img/home/account.png" alt="" /> -->
          <strong class="sub-tit font16">商家保证金:</strong>
          <span style="color:#24A813;margin-left: 10px;" v-if="shopInfo.marginState&&shopInfo.marginState==2">已缴纳保证金</span>
          <span style="color:red" v-else>未缴纳保证金</span>
          <span v-if="shopInfo.marginState&&shopInfo.marginState==2&&shopInfo.marginMoney<BZJmoney" style="color:red;margin-left: 20px;">保证金不足，请及时缴纳保证金！</span>
          <!-- <div class="shuaxin flex alc" @click="getInfo">
            <span class="el-icon-refresh-right"></span>
            <span class="font14">刷新</span>
          </div> -->

        </div>
        <div class="top-box">
          <strong class="line1">
            商家保证金(元)
          </strong><br/>
          <strong class="line2">
            {{shopInfo.marginMoney}}
          </strong><br/>
          <strong class="line3">
            应缴总额：{{BZJmoney}}元
          </strong>
          <div v-if="TIXIANING&&TIXIANING.type==2" style="color: #FFB5a1;font-size:12px;margin-bottom:5px">您有一笔 <span style="color:red;font-size:18px">{{TIXIANING.amount}}</span> 元的提现正在进行中...</div>
          <div class="btn">
            <el-button type="primary" size="mini" @click="openPayBZJ" v-if="shopInfo.marginState!=2&&!(TIXIANING&&TIXIANING.type==2)">缴纳保证金</el-button>
            <el-button type="primary" size="mini" @click="openPayBZJ" v-if="shopInfo.marginState==2&&shopInfo.marginMoney<BZJmoney">缴纳保证金</el-button>
            <el-button type="primary" size="mini" @click="openTixian" :disabled="shopInfo.marginState!=2||shopInfo.marginMoney<=0">提现</el-button>
            <el-button type="primary" size="mini" @click="openBZJOrder">保证金明细</el-button>
          </div>
        </div>
        <!-- <div class="bot-box">
          <strong class="tit">说明</strong>
          <div v-html="BZJdes"></div>
        </div> -->
        
      </div>
    </div>
    <!-- 提现账号 -->
    <div class="form-box">
      <div class="tit flex alc">
        <formSubTitVue :title="'收款账户'" :tip="''"></formSubTitVue>
        <div class="edit-btn font12" v-if="userInfo.userId == shopInfo.adminId">
          <el-button size="mini" type="primary" @click="addBackcard">添加</el-button>
        </div>
        <div v-else style="color:red">只有店铺管理员才能添加收款账户</div>

      </div>
      <div class="my_cards flex">
        <div class="item flex" v-for="item in cardsList" :key="item.id">
          <span class="icon">
            <img v-if="item.collectionType==2" src="https://imgage.maimaihao.com/yuduhulian/erp/static/icon/zfblogo.png" alt="">
            <img v-if="item.collectionType==3" src="https://imgage.maimaihao.com/yuduhulian/erp/static/icon/bankcard.png" alt="">
          </span>
          <span class="account">{{item.collectionAccount}}</span>
          <span class="name">{{item.collectionUserName}}</span>
          <el-button v-if="userInfo.userId == shopInfo.adminId" type="text" @click="delItem(item.id)">删除</el-button>
        </div>
      </div>
    </div>
    <div class="form-box">
      <div class="tit flex alc">
        <formSubTitVue :title="'店铺信息'" :tip="''"></formSubTitVue>
        <div class="edit-btn font12" v-hasPermi="['shopCenter:editInfo']" v-show="!isEditInfo" @click="isEditInfo = true;">
          <span class="el-icon-edit"></span>
          <span>修改信息</span>
        </div>
        <!-- <div class="edit-btn font12" style="margin-left:18px" >
          <span v-if="!shopInfo.fddOpenCorpId" @click="fadadaAuth">企业认证</span>
          <span v-else style="color:green" @click="fadadaAuth">已认证</span>
        </div> -->
      </div>
      <el-form ref="form" :rules="rules" :model="form" :inline="true" label-width="110px">
        <el-form-item label="店铺名称:" prop="tenantName">
          <el-input size="small" v-model="form.tenantName" placeholder="请输入店铺名称" :disabled="!isEditInfo"></el-input>
        </el-form-item>
        <el-form-item label="店铺域名:">
          <el-input size="small" v-model="form.domain" placeholder="域名不可自定义，请联系管理员" disabled></el-input>
        </el-form-item>
        <el-form-item label="域名备案号:">
          <el-input size="small" v-model="form.beian" placeholder="请填写域名对应的工信部备案号" :disabled="!isEditInfo"></el-input>
        </el-form-item>
        <br />
        <el-form-item label="企业全称:">
          <el-input size="small" v-model="form.enterpriseName" placeholder="请输入企业全称" :disabled="!isEditInfo"></el-input>
        </el-form-item>
        <el-form-item label="纳税人识别号:">
          <el-input size="small" v-model="form.businessLicenseNumber" placeholder="请输入纳税人识别号" :disabled="!isEditInfo"></el-input>
        </el-form-item>
        <!-- <el-form-item label="店铺地址:">
          <el-input size="small" v-model="form.otherShopAddress" placeholder="淘宝、PDD等电商平台店铺地址" :disabled="!isEditInfo"></el-input>
        </el-form-item> -->
        <br />
        <el-form-item label="绑定微信号:">
          <el-input size="small" v-model="form.wechatNumber" placeholder="请输入微信号" :disabled="!isEditInfo"></el-input>
        </el-form-item>
        <el-form-item label="绑定支付宝:">
          <el-input size="small" v-model="form.alipayNumber" placeholder="请输入支付宝" :disabled="!isEditInfo"></el-input>
        </el-form-item>
        <br />
        <el-form-item label="营业执照:">
          <el-input size="small" v-model="form.businessLicenseImg" placeholder="请输入营业执照" v-show="false"></el-input>
          <el-upload :action="uploadImgUrl" :show-file-list="false" list-type="picture-card" :limit="1" :disabled="!isEditInfo" :on-success="handleAvatarSuccess2">
            <img :src="form.businessLicenseImg" alt="" style="width:100%;height:100%" />
          </el-upload>
        </el-form-item><br />
        <el-form-item label="店铺简介:">
          <el-input size="small" type="textarea" rows="12" style="width:510px" v-model="form.introduction" placeholder="请输入店铺简介，此简介会展示在用户端" :disabled="!isEditInfo"></el-input>
        </el-form-item><br />
        <el-form-item v-if="isEditInfo">
          <div class="btn-box">
            <el-button size="small" @click="cancelEdit">取消</el-button>
            <el-button size="small" type="primary" @click="editUserInfo">确认修改</el-button>
          </div>

        </el-form-item>
      </el-form>
    </div>
    <payBZJ ref="payBZJ"></payBZJ>
    <BZJmingxi ref="BZJmingxi"></BZJmingxi>
    <tixian ref="tixian" @tixianover="getTixianing"></tixian>
    <chongzhi ref="chongzhi"></chongzhi>
    <userInfoSure ref="userInfoSure"></userInfoSure>
    <authDialog ref="authDialog"></authDialog>
    <addBankcardDialog ref="addBankcardDialog" @success="getList" @openAuthDialog="openAuth"></addBankcardDialog>
    <haibaoDialog ref="haibaoDialog"></haibaoDialog>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { tenantqiyerenzheng } from "@/api/system/user";
import { editShop } from "@/api/system/shopManage";
import formSubTitVue from "@/views/tenantPages/components/formSubTit.vue";
import payBZJ from "@/views/tenantPages/moneys/components/payBZJ.vue";
import BZJmingxi from "@/views/tenantPages/moneys/components/BZJmingxi";
import tixian from "@/views/tenantPages/moneys/components/tixian.vue";
import chongzhi from "../../moneys/components/chongzhijifen.vue";
import authDialog from "./authDialog";
import myMoneyApi from "@/api/financeCenter/myMoney.js";
import addBankcardDialog from "./addBankcardDialog.vue";
import haibaoDialog from "./haibaoDialog.vue";

import userInfoSure from "../../components/userInfoSure.vue";
export default {
  name: "",
  components: {
    formSubTitVue,
    payBZJ,
    BZJmingxi,
    tixian,
    chongzhi,
    userInfoSure,
    authDialog,
    addBankcardDialog,
    haibaoDialog,
  },
  data() {
    return {
      isEditName: false,
      isEditInfo: false,
      form: {
        realName: "",
      },
      uploadImgUrl: "",
      rules: {
        // realName: [
        //     { required: true, message: '请输入姓名', trigger: 'blur' }
        //   ],
      },
      BZJmoney: null,
      BZJdes: ``,
      cardsList: [],
      TIXIANING: "", //提现中的记录
    };
  },
  computed: {
    ...mapGetters(["userInfo", "shopInfo"]),
  },
  watch: {
    shopInfo: {
      handler(newVal) {
        if (newVal) this.form = JSON.parse(JSON.stringify(newVal));
      },
      immediate: true,
      deep: true,
    },
  },
  created() {
    this.uploadImgUrl = process.env.VUE_APP_BASE_API + "/upload/image";
    this.getBZJ()
    this.getTixianing();
    this.getList();
    this.$store.dispatch("getShopInfo")
  },
  methods: {
    // 打开我的海报
    myHaibao() {
      this.$refs.haibaoDialog.open();
    },
    // 签署入驻合同
    signFdd(){
      this.$refs.userInfoSure.open()
    },
    // 法大大认证
    fadadaAuth() {
      tenantqiyerenzheng({
        tenantId: this.userInfo.tenantId,
      }).then((res) => {
        console.log("%c Line:276 🍺 res", "color:#6ec1c2", res);
        if (res.msg && res.msg.incluse("http")) {
          window.open(res.msg);
          this.$alert("认证完成请点击确认！");
          this.$store.dispatch("getShopInfo", this.form.tenantId);
        }
      });
    },
 
    // 实名认证
    openAuth() {
      // if(this.shopInfo.authType==4){
      //   return
      // }
      this.$refs.authDialog.open();
    },
  
    // 获取保证金金额
    getBZJ() {
      this.getDicts("marginMoney").then((res) => {
        //console.log("%c Line:271 🥕 res", "color:#42b983", res);
        if (res.data && res.data.length) {
          this.BZJmoney = res.data[0].dictValue;
          this.BZJdes = res.data[0].remark?res.data[0].remark.replace(/\n/g, "<br/>"):'';
        }
      });
    },
    getInfo() {
      this.$store.dispatch("getShopInfo", this.userInfo.tenantId);
      this.getTixianing();
    },
    mingxi(path) {
      this.$router.push({
        path: path,
      });
    },
    // 点击提现按钮
    tixianFn() {
      if(this.shopInfo.marginState==2&&this.shopInfo.marginMoney<this.BZJmoney){
        this.$message.error('保证金不足，请缴纳保证金后再提现！')
        return
      }
      this.$refs.tixian.open(null);
    },
    // 点击充值
    chongzhijifen() {
      this.$refs.chongzhi.open();
      // this.$refs.paySuccess.open();
    },
    // 删除一个收款账户
    delItem(id) {
      this.$confirm("确认删除该提现账户吗", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          myMoneyApi.delBackcardListOne(id).then((res) => {
            this.$message.success(res.msg);
            this.getList();
          });
        })
        .catch(() => {});
    },
    // 查询已绑定的收款账户
    async getList() {
      let res1 = await myMoneyApi.getBackcardList({partyType:1});
      this.cardsList = res1.rows;
    },
    // 打开添加账户的弹窗
    addBackcard() {
      this.$refs.addBankcardDialog.open();
    },
    // 查询是否有正在提现的记录
    getTixianing() {
      myMoneyApi
        .withdrawalRecordList({ pageNum: 1, pageSize: 3, state: 1 })
        .then((res) => {
          if (res && res.rows.length && res.rows[0].state == 1) {
            this.TIXIANING = res.rows[0];
          } else {
            this.TIXIANING = "";
          }
        });
    },

    editUserInfo() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.isEditName = false;
          editShop(this.form).then((response) => {
            this.$modal.msgSuccess("修改成功");
            this.$store.dispatch("getShopInfo", this.form.tenantId);
            this.isEditInfo = false;
          });
        } else {
          //console.log("error submit!!");
          return false;
        }
      });
    },

    // 图片上传成功
    handleAvatarSuccess(res, file) {
      if (res.code == 200) {
        let url = res.data.filePath;
        this.form.avatar = url;
        this.editUserInfo();
      }
    },
    // 图片上传成功 营业执照
    handleAvatarSuccess2(res, file) {
      if (res.code == 200) {
        this.form.businessLicenseImg = res.data.filePath;
      }
    },
    // 取消修改
    cancelEdit() {
      this.form = JSON.parse(JSON.stringify(this.shopInfo));
      this.isEditInfo = false;
    },
    // 打开缴纳保证金的窗口
    openPayBZJ() {
      const money = Math.round((this.BZJmoney - this.shopInfo.marginMoney)*100)/100
      this.$refs.payBZJ.open(money,this.BZJmoney||0);
    },
    // 打开保证金明细
    openBZJOrder() {
      this.$refs.BZJmingxi.open();
    },
    // 保证金提现
    openTixian() {
      this.$store.dispatch("getShopInfo");
      this.$refs.tixian.open(null, "bzj");
    },
  },
};
</script>

<style scoped lang="scss">
.user-set-box {
  min-height: calc(100vh - 160px);
  padding: 25px 16px;
  background-color: $fff;
  margin-top: 16px;
  background-image: url("https://imgage.maimaihao.com/yuduhulian/erp/static/img/shopSetting/bg.png");
  background-size: 223px 186px;
  background-repeat: no-repeat;
  background-position: 90% 30px;
  .head-img {
    margin-right: 16px;
    position: relative;
    width: 75px;
    ::v-deep .el-upload {
      width: 75px;
      height: 75px;
      border: none;
      .btn {
        color: $fff;
      }
    }
    img {
      width: 100%;
      height: 75px;
      border-radius: 50%;
    }
    .btn {
      width: 100%;
      height: 18px;
      background-color: $primary;
      text-align: center;
      line-height: 18px;
      cursor: pointer;
      border-radius: 9px;
      position: absolute;
      bottom: 0;
    }
  }
  .name-box {
    padding-top: 10px;
    .shopname {
      line-height: 30px;
      .edit-btn {
        color: $acativeTxtColor;
        margin-left: 10px;
        cursor: pointer;
      }
    }
    .id-txt {
      color: $color999;
    }
    .qianyue {
      color: $yellow;
      cursor: pointer;
      .icon {
        width: 12px;
        height: 12px;
        margin-right: 3px;
      }
      .yi {
        .icon {
          background: url("https://imgage.maimaihao.com/yuduhulian/erp/static/img/shopSetting/yiqianyue.png")
            no-repeat 0 0 / 100% 100%;
        }
      }
      .wei {
        color: $grey;
        .icon {
          background: url("https://imgage.maimaihao.com/yuduhulian/erp/static/img/shopSetting/weiqianyue.png")
            no-repeat 0 0 / 100% 100%;
        }
      }
    }
  }
  .zichan {
    margin-top: 15px;
    text-align: center;
  }
  .baozhengjin {
    width: 515px;
    padding: 15px;
    border: 1px #ccc dashed;
    margin-left: 20px;
   
    .top-box {
      line-height: 26px;
      padding-top: 10px;
    }
    .line1 {
      font-size: 16px;
    }
    .line2 {
      font-size: 24px;
    }
    .line3 {
    }
    .btn {
      margin-top: 15px;
    }
    .bot-box {
      text-align: left;
      margin-top: 15px;
      .tit {
        font-size: 16px;
      }
    }
  }
  .zhanghu {
    width: 515px;
    // min-width: 337px;
    border: 1px #ccc dashed;
    padding: 15px;
    background-color: #fff;
    margin-left: 20px;

    .btn-box {
      .icon {
        display: inline-block;
        vertical-align: top;
        width: 12px;
        height: 12px;
        background-image: url("https://imgage.maimaihao.com/yuduhulian/erp/static/img/shopSetting/tx.png");
        background-size: 12px 12px;
      }
    }

    .main-box {
      min-width: 280px;
      margin-top: 20px;
      & > div {
        width: 50%;
      }
    }
    .money-num {
      line-height: 40px;
    }
    .shuaxin {
      cursor: pointer;
      color: $green;
      margin-left: 10px;
    }
    .jifen-box {
      margin-left: 20px;
    }
  }
  .form-box {
    margin-top: 30px;
    .tit {
      margin-bottom: 20px;
      .edit-btn {
        color: $acativeTxtColor;
        cursor: pointer;
      }
    }
    .btn-box {
      width: 915px;
      text-align: center;
    }
  }
  // .btn-box{
  //   width: 915px;
  //   text-align: center;
  // }
}
.my_cards {
  img {
    width: 50px;
    margin-right: 15px;
  }
  .item {
    width: 360px;
    height: 60px;
    padding: 0 15px;
    border-radius: 10px;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 0 2px 0 rgba(0, 0, 0, 0.3);
    margin-bottom: 10px;
    margin-right: 15px;
    .account {
      font-size: 16px;
      font-weight: bold;
    }
    .name {
      font-size: 16px;
      font-weight: bold;
    }
  }
}
</style>
